package com.yxhl.zoume.utils;

import android.content.Context;
import android.text.TextUtils;

import com.github.pwittchen.prefser.library.Prefser;
import com.yxhl.zoume.UIConstants;

/**
 * Created by sugarya on 16/4/27.
 */
public class DiskCacheUtils {

    private static DiskCacheUtils instance = null;
    private Prefser prefser;

    public DiskCacheUtils(Context context) {
        if (null == prefser) {
            prefser = new Prefser(context);
        }
    }

    public static DiskCacheUtils getInstance(Context context) {
        if (instance == null) {
            synchronized (DiskCacheUtils.class) {
                if (instance == null) {
                    instance = new DiskCacheUtils(context);
                }
            }
        }
        return instance;
    }

    public void saveLocationCity(String city) {
        if (!TextUtils.isEmpty(city)) {
            prefser.put(UIConstants.DiskCache.KEY_LOCATION_CITY, city);
        }
    }

    public String getLocationCity() {
        return prefser.get(UIConstants.DiskCache.KEY_LOCATION_CITY, String.class, "");
    }


    public void saveDeviceToken(String token) {
        if (!TextUtils.isEmpty(token)) {
            prefser.put(UIConstants.DiskCache.KEY_DEVICE_TOKEN, token);
        }
    }

    public String getDeviceToken() {
        return prefser.get(UIConstants.DiskCache.KEY_DEVICE_TOKEN, String.class, "");
    }

    //快车订单编号
    public void saveSpecialCarOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            prefser.put(UIConstants.DiskCache.KEY_SPECIAL_CAR_ORDER_ID, orderId);
        }
    }

    public String getSpecialCarOrderId() {
        return prefser.get(UIConstants.DiskCache.KEY_SPECIAL_CAR_ORDER_ID, String.class, "");
    }

    //公务车订单编号
    public void saveOfficialCarOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            prefser.put(UIConstants.DiskCache.KEY_OFFICIAL_CAR_ORDER_ID, orderId);
        }
    }

    public String getOfficialCarOrderId() {
        return prefser.get(UIConstants.DiskCache.KEY_OFFICIAL_CAR_ORDER_ID, String.class, "");
    }

    //专车订单编号
    public void saveExpressCarOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            prefser.put(UIConstants.DiskCache.KEY_EXPRESS_CAR_ORDER_ID, orderId);
        }
    }

    public String getExpressCarOrderId() {
        return prefser.get(UIConstants.DiskCache.KEY_EXPRESS_CAR_ORDER_ID, String.class, "");
    }


    public void putZouMeBusDialogShowFlag() {
        prefser.put(UIConstants.DiskCache.ZOU_ME_BUS_DIALOG_SHOW, "false");
    }

    public String getZouMeBusDialogShowFlag() {
        return prefser.get(UIConstants.DiskCache.ZOU_ME_BUS_DIALOG_SHOW, String.class, "true");
    }
}
